//
//  NativeFileManager.m
//  FFmpeg_X264_Codec
//
//  Created by luwinglee on 16/1/9.
//  Copyright © 2016年 suntongmian@163.com. All rights reserved.
//

#import "NativeFileManager.h"
 char read_buf[MAX_READ_FILE_SIZE] = {'\0'};
@implementation NativeFileManager
{
    FILE *m_file;
}

-(id) init
{
    self = [super init];
    if (self != nil) {
        return self;
    }
    else
        return nil;
}

-(int) createFileManager:(char *) filePath
{
    m_file = fopen(filePath, "rb");
    if (!m_file) {
        NSLog(@"open read file error\n");
        return -1;
    }
    
    return 0;
}

-(char *) readFileData:(int) maxReadSize andReadSize:(int *)readSize
{
    int ret = -1;
    if (maxReadSize > MAX_READ_FILE_SIZE) {
        maxReadSize = MAX_READ_FILE_SIZE;
    }
    
   
    ret = (int)fread(read_buf, 1, maxReadSize, m_file);
    if (ret <= 0) {
        NSLog(@"read file eof\n");
        return NULL;
    }
    *readSize = ret;
    
    return read_buf;
}

-(void) closeFileManager
{
    if (m_file) {
        fclose(m_file);
    }
}

@end

